<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <fieldset class="layui-elem-field">
                <legend>微信支付设置</legend>
                <div class="layui-field-box">
                    <div class="layui-card">
                        <div class="layui-card-header">微信支付设置</div>
                        <div class="layui-card-body" pad15>
                            <div class="layui-form" wid100 lay-filter="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">小程序Appid</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <input type="text" name="appid" lay-verify="required" value="{$find.appid}" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">小程序密钥</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <input type="password" name="secret_key" lay-verify="required" value="{$find.secret_key}" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">商户号</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <input type="text" name="merchant" lay-verify="required" value="{$find.merchant}" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">商户号秘钥</label>
                                    <div class="layui-input-inline" style="width: 300px;">
                                        <input type="password" name="merchant_key" lay-verify="required" value="{$find.merchant_key}" class="layui-input">
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">支付证书</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="certificate" lay-verify="required" value="{$find.certificate}" placeholder="支付证书" autocomplete="off" class="layui-input">
                                    </div>
                                    <button style="float: left;" type="button" class="layui-btn" id="test">上传文件</button>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">支付证书秘钥</label>
                                    <div class="layui-input-inline">
                                        <input type="text" name="certificate_key" lay-verify="required" value="{$find.certificate_key}" placeholder="支付证书秘钥" autocomplete="off" class="layui-input">
                                    </div>
                                    <button style="float: left;" type="button" class="layui-btn" id="test2">上传文件</button>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="set_website">确认保存</button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </fieldset>
        </div>
    </div>
</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'set'], function(){
        var $ = layui.jquery,
                upload = layui.upload,
                form = layui.form;

        upload.render({
            elem: '#test'
            ,url: "{:url('System/certificate')}"
            ,accept: 'file'
            ,done: function(e){
                //如果上传失败
                if(e.code == 400){
                    return layer.msg(e.msg);
                }
                //上传成功
                $("input[name=certificate]").val(e.data);
                layer.msg("上传成功", {icon: 1});
            }
        });

        upload.render({
            elem: '#test2'
            ,url: "{:url('System/certificate')}"
            ,accept: 'file'
            ,done: function(e){
                //如果上传失败
                if(e.code == 400){
                    return layer.msg(e.msg);
                }
                //上传成功
                $("input[name=certificate_key]").val(e.data);
                layer.msg("上传成功", {icon: 1});
            }
        });

        form.on('submit(set_website)', function(data){
            var field = data.field;
            $.post("{:url('System/secret')}", {field:field}, function(e){
                if (e == 1){
                    layer.msg('修改成功', {icon: 1});
                }else{
                    layer.msg('修改失败', {icon: 2});
                }
            })
        });

    });
</script>
</body>
</html>